﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using WMS.BasicData.ProductDetails;
using WMS.BasicData.Vendors;
using WMS.BasicData.Vendors.DTO;
using WMS.Common;
using WMS.InventoryManagement.Differences;
using WMS.InventoryManagement.TakeStocks;
using WMS.InventoryManagement.TakeStocks.DTO;
using WMS.Web.Controllers.BasicData.Vendors;

namespace WMS.Web.Controllers.InventoryManagement.TakeStocks
{
    /// <summary>
    /// 盘点控制器
    /// </summary>
    public class TakeStockController : Controller
    {
        /// <summary>
        /// 盘点接口
        /// </summary>
        private readonly ITakeStockAppService _takeStockAppService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public TakeStockController(ITakeStockAppService takeStockAppService)
        {
            _takeStockAppService = takeStockAppService;
        }

        /// <summary>
        /// 接口
        /// </summary>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 录入
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        public IActionResult Update(int Id)
        {
            ViewBag.Id = Id;
            return View();
        }



        /// <summary>
        /// 获取供应商（分页）
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="limit">页容量</param>
        /// <param name="chineseName">中文名字</param>
        /// <returns>返回对应数据</returns>
        [HttpGet]
        public async Task<JsonResult> GetTakeStock(int page, int limit)
        {
            var pagedResult = await _takeStockAppService.GetTakeStock(page, limit);
            return Json(new { data = pagedResult, code = 0 });
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="vendor">供应商信息</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<int> AddTakeStock(TakeStock takeStock)
        {
            var i = await _takeStockAppService.AddTakeStock(takeStock);
            return i;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<int> DeleteTakeStock(int Id)
        {
            var i = await _takeStockAppService.DeleteTakeStock(Id);
            return i;
        }

        /// <summary>
        /// 获取对应数据
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public async Task<JsonResult> BackfillData(int Id)
        {
            var vendor = await _takeStockAppService.BackfillData(Id);
            return Json(new { data = vendor });
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateTakeStock(TakeStockDTO takeStock)
        {
            var i = await _takeStockAppService.UpdateTakeStock(takeStock);
            return i;
        }


        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetProductDetail()
        {
            var productDetailList = await _takeStockAppService.GetProductDetail();
            return Json(new { data = productDetailList });
        }
    }
}
